<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="vue.js"></script>
<body>
    <div id="app">
        <ul>
            <!-- 静态属性 -->
            <!-- <school :school-name="'清华'"></school> -->
            <school v-for="(item,index) in schoolList" :school-name="item" :key="index" :count="index" v-on:changename="chooseName"></school>
        </ul>
        <h3 style="color:#872657">选中学校:{{this.chooseSchool}}</h3>
    </div>
    <script>
        Vue.component('school',{
            props:['schoolName','count'],
            template:`
            <li>
                <p>序号：{{count}}------学校：{{schoolName}}</p>
                <button @click="changeEvent(schoolName)">选中</button>
            </li>
            `,
            data:function(){
                return{

                }
            },
            methods:{
                changeEvent(name){
                    console.log(name);
                    this.$emit('changename',name);
                }
            },
        })

        var vm = new Vue({
            el:'#app',
            data:{
                schoolList:['安阳师范学院','安阳工学院','河南护理学院'],
                chooseSchool:'',
            },
            methods:{
                chooseName:function(name){
                    console.log('触发选择事件');
                    this.chooseSchool = name;
                }
            }
        })
    </script>
</body>
</html>